<h1>
  <my-global-icon iconName="cog" aria-hidden="true"></my-global-icon>
  <ng-container i18n>Two factor authentication</ng-container>
</h1>

<div i18n *ngIf="twoFactorAlreadyEnabled === true" class="root already-enabled">
  Two factor authentication is already enabled.
</div>

<div class="root" *ngIf="twoFactorAlreadyEnabled === false">
  <ng-container *ngIf="step === 'request'">
    <form role="form" (ngSubmit)="requestTwoFactor()" [formGroup]="formPassword">

      <label i18n for="current-password">Your password</label>
      <div class="form-group-description" i18n>Confirm your password to enable two factor authentication</div>

      <my-input-text
        formControlName="current-password" inputId="current-password" i18n-placeholder placeholder="Current password"
        [formError]="formErrorsPassword['current-password']" autocomplete="current-password"
      ></my-input-text>

      <input class="peertube-button orange-button mt-3" type="submit" i18n-value value="Confirm" [disabled]="!formPassword.valid">
    </form>
  </ng-container>

  <ng-container *ngIf="step === 'confirm'">

    <p i18n>
      Scan this QR code into a TOTP app on your phone. This app will generate tokens that you will have to enter when logging in.
    </p>

    <qrcode [qrdata]="twoFactorURI" [width]="256" level="Q"></qrcode>

    <div i18n>
      If you can't scan the QR code and need to enter it manually, here is the plain-text secret:
    </div>

    <div class="secret-plain-text">{{ twoFactorSecret }}</div>

    <form class="mt-3" role="form" (ngSubmit)="confirmTwoFactor()" [formGroup]="formOTP">

      <label i18n for="otp-token">Two-factor code</label>
      <div class="form-group-description" i18n>Enter the code generated by your authenticator app to confirm</div>

      <my-input-text
        [show]="true" formControlName="otp-token" inputId="otp-token"
        [formError]="formErrorsOTP['otp-token']" autocomplete="otp-token"
      ></my-input-text>

      <input class="peertube-button orange-button mt-3" type="submit" i18n-value value="Confirm" [disabled]="!formOTP.valid">
    </form>
  </ng-container>

</div>
